# initialization.py
# created from plugin_plugin/template_plugin_initialization_py
# copyright christopher steel, 2011, on behalf of Voice of Access
import os
cwd = os.getcwd()
current_app = os.path.join(cwd,'applications',request.application)
#initialization_file_path = os.path.join(current_app,'models','plugin_pdf_pyfpdf','000_uc_initialization.py')
initialization_file_path = os.path.join(current_app,'models','000_uc_initialization.py')

# create an initialization file if we do not have one
if not 'initialization_file_created' in globals():
    if not os.path.exists(initialization_file_path):
        our_file = open(initialization_file_path,"w")
        our_text = '# file created by plugin_pdf_pyfpdf\n'
        our_text += 'initialization_file_created = True\n'
        our_file.writelines(our_text)
        our_file.close()
else:
    print('models/plugin_pdf_pyfpdf/initialization.py found')
    print('initialization_file_created globals')


if not 'group_plugin_pdf_pyfpdf_admin_created' in globals():
    if not db(db.auth_group.role=='plugin_pdf_pyfpdf_admin').select(): 
        db.auth_group.insert(role='plugin_pdf_pyfpdf_admin',description='user to administer plugin_pdf_pyfpdf')
        our_file = open(initialization_file_path,"a")
        our_text = '# entry created by plugin_pdf_pyfpdf\n'
        our_text += 'group_plugin_pdf_pyfpdf_admin_created = True\n'
        our_file.write(our_text)
        our_file.close()
else:
    print('models/plugin_pdf_pyfpdf/initialization.py found')
    print('group_plugin_pdf_pyfpdf_admin_created globals')
